package com.thingsgrid.physicalmodel.controller;

import com.thingsgrid.physicalmodel.entity.PhysicalModel;
import com.thingsgrid.physicalmodel.entity.PhysicalModelBody;
import com.thingsgrid.physicalmodel.service.IPhysicalModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 功能说明：
 *
 * @author 李龙飞
 * @since 2019/9/10 17:14
 */

@RestController
@RequestMapping("physicalmodel")
@Api("物模型")
@AllArgsConstructor
public class PhysicalModelController {

	@Autowired
	private IPhysicalModelService physicalModelService;

	/**
	 * 新增
	 */
	@PostMapping("/submit")
	@ApiOperation(value = "新增", notes = "传入function", position = 1)
	public R save(PhysicalModelBody physicalModelBody) {
		return R.status(physicalModelService.savePhysical(physicalModelBody.getObj(),1));
	}

	/**
	 * 删除
	 */
	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入id", position = 2)
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String physicalModelId) {
		return R.status(physicalModelService.removePhysical(physicalModelId));
	}

	/**
	 * 修改
	 * @return
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改", notes = "physicalModel", position = 3)
	public R update(PhysicalModelBody physicalModelBody) {
		return R.status(physicalModelService.updatePhysical(physicalModelBody.getObj()));
	}

	/**
	 * 查找所有
	 */
	@GetMapping("/selectAll")
	@ApiOperation(value = "查询所有", notes = "", position = 4)
	public R<List<PhysicalModel>> selectAll() {
		return R.data(physicalModelService.findAll());
	}

	/**
	 * 根据functionId查信息
	 */
	@GetMapping("/findoneById")
	@ApiOperation(value = "查询一个", notes = "", position = 5)
	public R<PhysicalModel> selectById(@ApiParam(value = "physicalModelId", required = true) @RequestParam String physicalModelId) {
		return R.data(physicalModelService.findPhysicalById(physicalModelId));
	}

	/**
	 * 分页查询
	 */
	@GetMapping("/list")
	@ApiOperation(value = "分页", notes = "传入页数和每页显示的条数", position = 6)
	public R<Map<String, Object>> pageList(@ApiParam(value = "页数和条数", required = true)
								   @RequestParam Integer pageIndex, Integer pageSize) {
		return R.data(physicalModelService.findAll(pageIndex, pageSize));
	}

	/**
	 * 根据查信息
	 */
	@GetMapping("/findByName")
	@ApiOperation(value = "查询", notes = "", position = 5)
	public R<List<PhysicalModel>> findOneByName(@ApiParam(value = "physicalName", required = true) @RequestParam String physicalName) {
		return R.data(physicalModelService.findOneByName(physicalName));
	}
}
